import Request from "@/api/Request";
import PathVariable from "@/domain/po/PathVariable";
import type DataSourceInfoFormBO from "@/domain/bo/DataSourceInfoFormBO";
import type Page from "@/domain/bo/PageBO";
import DataSourceInfoVO from "@/domain/vo/DataSourceInfoVO";
import JlPage from "@/domain/po/JlPage";

class DataSourceService {

    /**
     * 获取数据
     * @param id
     */
    public get(id: string): Promise<DataSourceInfoVO> {
        return Request
            .build("/api/data/source/get/{id}")
            .pathVariable([new PathVariable("id", id)])
            .doGet(undefined);
    }


    /**
     * 列表查询
     */
    public list(page: Page): Promise<JlPage<DataSourceInfoVO>> {
        return Request
            .build("/api/data/source/list")
            .doGet({
                page: page.page,
                pageSize: page.pageSize
            });
    }

    /**
     * Mysql测试连接
     */
    public testConnection(bo: DataSourceInfoFormBO): Promise<boolean> {
        return Request
            .build("/api/mysql/data/source/test/connection")
            .doPost(bo);
    }

    /**
     * Mysql测试连接
     */
    public testConnectionById(id: string): Promise<boolean> {
        return Request
            .build("/api/mysql/data/source/{id}/test/connection")
            .pathVariable([new PathVariable("id", id)])
            .doGet(undefined);
    }

    /**
     * Mysql获取表
     */
    public tableList(id: string): Promise<Array<String>> {
        return Request
            .build("/api/mysql/data/source/{id}/tables")
            .pathVariable([new PathVariable("id",id)])
            .doGet(undefined);
    }

    /**
     * 添加
     */
    public add(bo: DataSourceInfoFormBO) {
        return Request
            .build("/api/data/source/add")
            .doPost(bo);
    }

    /**
     * 编辑
     */
    public edit(bo: DataSourceInfoFormBO) {
        return Request
            .build("/api/data/source/edit/{id}")
            .pathVariable([new PathVariable("id", bo.id)])
            .doPut(bo);
    }

    /**
     * 删除
     */
    public del(ids: string[]) {
        return Request
            .build("/api/data/source/del")
            .doDelete(ids);
    }
}

export default new DataSourceService();
